{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Quantum Gates in Qiskit\n",
    "Start by some typical setup and definition of useful functions, which you are encouraged to look at.\n",
    "\n",
    "Then, head to the [exercises start](#Exercises-Start-Here) to start coding!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister\n",
    "from qiskit import execute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Choose the drawer you like best:\n",
    "from qiskit.tools.visualization import matplotlib_circuit_drawer as draw\n",
    "#from qiskit.tools.visualization import circuit_drawer as draw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit import IBMQ\n",
    "IBMQ.load_account() # make sure you have setup your token locally to use this"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Utils for visualizing experimental results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def show_results(D):\n",
    "    # D is a dictionary with classical bits as keys and count as value\n",
    "    # example: D = {'000': 497, '001': 527}\n",
    "    plt.bar(range(len(D)), list(D.values()), align='center')\n",
    "    plt.xticks(range(len(D)), list(D.keys()))\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Utils for executing circuits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Aer backends:  [<QasmSimulator('qasm_simulator') from Aer()>, <QasmSimulatorPy('qasm_simulator_py') from Aer()>, <StatevectorSimulator('statevector_simulator') from Aer()>, <StatevectorSimulatorPy('statevector_simulator_py') from Aer()>, <UnitarySimulator('unitary_simulator') from Aer()>, <CliffordSimulator('clifford_simulator') from Aer()>]\n"
     ]
    }
   ],
   "source": [
    "from qiskit import Aer\n",
    "# See a list of available local simulators\n",
    "print(\"Aer backends: \", Aer.backends())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IBMQ Backends:  [<IBMQBackend('ibmqx4') from IBMQ()>, <IBMQBackend('ibmqx5') from IBMQ()>, <IBMQBackend('ibmqx2') from IBMQ()>, <IBMQBackend('ibmq_16_melbourne') from IBMQ()>, <IBMQBackend('ibmq_qasm_simulator') from IBMQ()>]\n"
     ]
    }
   ],
   "source": [
    "# see a list of available remote backends (these are freely given by IBM)\n",
    "print(\"IBMQ Backends: \", IBMQ.backends())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Execute locally"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# execute circuit and either display a histogram of the results\n",
    "def execute_locally(qc, draw_circuit=False):\n",
    "    # Compile and run the Quantum circuit on a simulator backend\n",
    "    backend_sim = Aer.get_backend('qasm_simulator')\n",
    "    job_sim = execute(qc, backend_sim)\n",
    "    result_sim = job_sim.result()\n",
    "    result_counts = result_sim.get_counts(qc)\n",
    "    \n",
    "    # Print the results\n",
    "    print(\"simulation: \", result_sim, result_counts)\n",
    "    \n",
    "    if draw_circuit: # draw the circuit\n",
    "        draw(qc)\n",
    "    else: # or show the results\n",
    "        show_results(result_counts)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Execute remotely"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit.backends.ibmq import least_busy\n",
    "import time\n",
    "# Compile and run on a real device backend\n",
    "def execute_remotely(qc, draw_circuit=False):\n",
    "    if draw_circuit: # draw the circuit\n",
    "        draw(qc)\n",
    "    try:\n",
    "        # select least busy available device and execute.\n",
    "        least_busy_device = least_busy(IBMQ.backends(simulator=False))\n",
    "        print(\"Running on current least busy device: \", least_busy_device)\n",
    "\n",
    "        # running the job\n",
    "        job_exp = execute(qc, backend=least_busy_device, shots=1024, max_credits=10)\n",
    "\n",
    "        lapse, interval = 0, 10\n",
    "        while job_exp.status().name != 'DONE':\n",
    "            print('Status @ {} seconds'.format(interval * lapse))\n",
    "            print(job_exp.status())\n",
    "            time.sleep(interval)\n",
    "            lapse += 1\n",
    "        print(job_exp.status())\n",
    "        exp_result = job_exp.result()\n",
    "        result_counts = exp_result.get_counts(qc)\n",
    "\n",
    "        # Show the results\n",
    "        print(\"experiment: \", exp_result, result_counts)\n",
    "        if not draw_circuit: # show the results\n",
    "            show_results(result_counts)\n",
    "    except:\n",
    "        print(\"All devices are currently unavailable.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Building the circuit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def new_circuit(size):\n",
    "    # Create a Quantum Register with size qubits\n",
    "    qr = QuantumRegister(size)\n",
    "\n",
    "    # Create a Classical Register with size bits\n",
    "    cr = ClassicalRegister(size)\n",
    "\n",
    "    # Create a Quantum Circuit acting on the qr and cr register\n",
    "    return qr, cr, QuantumCircuit(qr, cr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "<h1 align=\"center\">Exercises Start Here</h1>\n",
    "\n",
    "Make sure you ran all the above cells in order, as the following exercises use functions defined and imported above."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Adding Gates"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Hadamard\n",
    "This gate is required to make superpositions.\n",
    "\n",
    "**TASK:** Create a new circuit with 2 qubits using `new_circuit` (very useful to reconstruct your circuit in Jupyter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "qr, cr, circuit = new_circuit(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Add a Hadamard on the _least important_ qubit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# H gate on qubit 0\n",
    "circuit.h(qr[0]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Perform a measurement on that qubit to the first bit in the register"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# measure the specific qubit\n",
    "circuit.measure(qr[0], cr[0]); # ; hides the output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** check the result using `execute_locally` test both `True` and `False` for the `draw_circuit` option"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "simulation:  COMPLETED {'00': 515, '01': 509}\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAADYCAYAAADGfS49AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAElNJREFUeJzt3X9MU+f+B/A3AiJKS7GCfCcWJpl3wsR21em8V1Hn7Iz8iKLJTRRDjIElGuMgpI0ukWxqiluYujuyS3RiNGZz0QlMI+qNkhlN42RI9I8tSAXxu01BSx2IBny+f/ilA+FiO9oe+vh+JSdpznlOP59S3z6nTwsNEkIIEJGURindABH5DgNOJDEGnEhiDDiRxBhwIokx4EQSY8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wWWCwWt/vqvf+havuapbjML3UoMFnNuW6NUzTgNTU1CAoKwurVqwccU6lUAJ7Npn05HA6o1WoAQHl5Oc6dO+d6jewt7tT2NXefQKKhKHqJ3traiqioKAQFBQ04ptFooNPpUFtb69rX2NgIp9PputyOi4vzSV/u1CYKBIrO4EajEXa7HVVVVVi2bBmcTidsNhtMJhMAIDc3F8XFxVi4cCG0Wi3MZjNMJhMSEhJ83puStQFeotPQ3L7CU3qVr7y8XEydOlWMGzdOxMbGii1btriOdXd3i4KCAqHVakVERIRYvny5uHfvXr/zDxw4ID7++OMha+zYsUMkJSV51Jc7tYlGuiAhhPDt/zW+VV5ejpaWliEX2YheVgEd8HXr1sFms+Hx48eYNm0aqqqqlG6JaEQJ6IAT0dAU/6ALEfkOA04kMQacSGIMOJHEGHAiiTHgRBJjwIkkxoATSYwBJ5IYA04kMQacSGIMOJHEGHAiiTHgRBJjwIkkxoATSYwBJ5IYA04kMQacSGIMOJHEGHAiiTHgRBJjwIkkxoATSYwBJ5IYA04kMQacSGL/B5vQWv7KNH+ZAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2645a901b70>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Try both commands:\n",
    "execute_locally(circuit,draw_circuit=True)\n",
    "# execute_locally(circuit,draw_circuit=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The result should be something like `COMPLETED {'00': 516, '01': 508}`.\n",
    "\n",
    "**TASK:** What does this mean?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> That we got our superposition as expected, approximately 50% of the experiments yielded 0 and the other 50% yielded 1."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "### X Gate (Pauli-X)\n",
    "This gate is also referred to as a bit-flip.\n",
    "\n",
    "\n",
    "**TASK:** Create a new circuit with 2 qubits using `new_circuit` (very useful to reconstruct your circuit in Jupyter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "qr, cr, circuit = new_circuit(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Add an X gate on the _most important_ qubit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# H gate on qubit 1\n",
    "circuit.x(qr[1]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Perform a measurement on that qubit to the first bit in the register"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# measure the specific qubit\n",
    "circuit.measure(qr[1], cr[0]); # ; hides the output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** check the result using `execute_locally` test both `True` and `False` for the `draw_circuit` option"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "simulation:  COMPLETED {'01': 1024}\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAADYCAYAAADGfS49AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAEwNJREFUeJzt3X1Mk+e/x/FPBYcc6NMqyomcgpD4y2QqrCqo48dwxM6IMkW3GSUzxrAEN58JRJdl8WlFJ0Gn/sGc4GTG4+IyNHNoXJRtarr5QJzLskRBoJ4ZgUgbwYrW6/xh7M+KDy20d8vl55U0cTfXzfVF97Z3HwSVEEKAiKQ0INgDEFHgMHAiiTFwIokxcCKJMXAiiTFwIokxcCKJMXAiiTFwIokxcCKJMXAi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EzRmYxGo9i1a5f7vy9fviwAiMbGRkXnIOqLoN+DHzx4EDNmzEBBQQGam5vR0tKCRYsW+XUPi8WC0aNHe73ebrejubkZJpPJfSwpKQkajQYXL17062xEgaTsA9vHdHZ24oMPPsDWrVuRl5cHAIiIiIDZbPbq/OzsbNTX12PZsmX4+OOPn7qupKQEJSUlXs/lcDgAAFqt1uO4TqdzfyzQSkorFNmH+idLcYFX64IaeF1dHVQqFebNm9er86uqqnD8+HH3Y2R/UavVAB7ckz+qo6MDGo3Gr3s9jbd/gETPEtRL9La2Nuj1eqhUql6dHxcX5+eJHtDpdDAajTh//rz7WENDAxwOh0+X+kTBFtR7cJPJhMbGRhw+fBjTpk2Dw+GA1Wp1X6K7XC7cvXsX3d3dAACn0wngwWV8b/9S8FZBQQFKS0uRlZUFg8GA4uJimM1mJCQkBHTfh3iJTs/i9RVesJ/lq6qqEiNGjBBRUVEiNjZWrF692v2xyspKAaDH7dFnsisrK8W6deueuceGDRvEyJEjfZrr3r17YuXKlcJgMIjo6Ggxc+ZM0dra6tPnIAo2lRBCBOyvGQVUVVXBZrM980k2ohdVvw584cKFsFqtuHPnDl555RUcPnw42CMRhZR+HTgRPVvQ3+hCRIHDwIkkxsCJJMbAiSTGwIkkxsCJJMbAiSTGwIkkxsCJJMbAiSTGwIkkxsCJJMbAiSTGwIkkxsCJJMbAiSTGwIkkxsCJJMbAiSTGwIkkxsCJJMbAiSTGwIkkxsCJJMbAiSTGwIkkxsCJJPb/te/mzvSHUiIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x264713fb978>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Try both commands:\n",
    "execute_locally(circuit,draw_circuit=True)\n",
    "# execute_circuit(circuit,draw_circuit=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Free flow\n",
    "At this stage you are encouraged to repeat (and tweek as you wish) the above tasks for the Hadamard and X gates, especially on single qubit gates."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "### CNOT (Controlled NOT, Controlled X gate)\n",
    "This gate uses a control qubit and a target qubit to \n",
    "\n",
    "\n",
    "**TASK:** Create a new circuit with 2 qubits using `new_circuit` (very useful to reconstruct your circuit in Jupyter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "qr, cr, circuit = new_circuit(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Add a CNOT gate with the _least important_ qubit as the control and the other as the target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "# CNOT gate\n",
    "circuit.cx(qr[0], qr[1]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Perform a measurement on the qubits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# measure the specific qubit\n",
    "circuit.measure(qr, cr); # ; hides the output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** check the result using `execute_locally` test both `True` and `False` for the `draw_circuit` option"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "simulation:  COMPLETED {'00': 1024}\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASYAAADYCAYAAABGK04HAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAG1VJREFUeJzt3XtQU2f+P/B3iGgVSIKARVFA0a6KWm6KYh2aqqVb74qzW9cLWsSutop4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MjMzMWPGDOTm5kKv19s81rFjR6f0pdPpEBgYiJMnT1rHiouLYbFYnuhQkuTFUJKTS1dMkZGRuHTpEnJzczFs2DBYLBYYjUbExcUBANLT07F06VLk5+ejb9/6X+J1lqSkJKxatQp6vR4+Pj5ITU1FXFycYie+eShHzxq7jgKEi2VlZYmXXnpJeHh4CH9/f7Fo0SLrYwBEixYthIeHh83tUZmZmWLZsmUN1lixYoXo2bOnXX1VV1eLefPmCR8fH+Hp6SnGjBkjbt68adc+iOjJSHG5wNPIysqCyWRy6MlvInKtZh1M06ZNg9FoxL1799CjRw/k5ua6uiUicoBmHUxE9Gxy+QWWRES1MZiISDoMJiKSDoOJiKTDYCIi6TCYiEg6DCYikg6DiYikw2AiIukwmIhIOgwmIpIOg4mIpMNgIiLpMJiISDoMJiKSDoOJiKTDYCIi6TCYiEg6DCYikg6DiYikw2AiIukwmIhIOgwmIpIOg4mIpMNgIiLpMJiISDoMJiKSzv8Cq8RfJ0Vs7m0AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x26471518a90>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Try both commands:\n",
    "execute_locally(circuit,draw_circuit=True)\n",
    "# execute_circuit(circuit,draw_circuit=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Since a single CNOT does not seem very powerful, go ahead and add a hadamard gate to the two qubits (before the CNOT gate) and redo the experiment (you can try this by using a single Hadamard on each qubit as well)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "qr, cr, circuit = new_circuit(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# H gate on 2 qubits\n",
    "circuit.h(qr);\n",
    "# CNOT gate\n",
    "circuit.cx(qr[0], qr[1]);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "# measure\n",
    "circuit.measure(qr, cr); # ; hides the output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "simulation:  COMPLETED {'00': 272, '01': 254, '10': 265, '11': 233}\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVMAAADYCAYAAABWSwDbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAHihJREFUeJzt3X1UlFUeB/AvL4LyMjPIq4nDgLtGKQoioplhaqGpaBnG5kvJKlurFkdzMW2LDF2wNqUt94SmeGr5I3pDlIMdNzNXbQ4bIku760YwAooiBIxSoMDdP1pnHUEZ9M48DH4/58w54537PPfHMzNfn5c7Mw5CCAEiIrotjkoXQETUHzBMiYgkYJgSEUnAMCUikoBhSkQkAcOUiEgChikRkQQMUyIiCRimREQSMEyJiCRgmBIRScAwJSKSgGFKRCQBw5SISAKGKRGRBAxTIiIJGKZERBIwTImIJGCYEhFJwDAlIpKAYUpEJAHDlIhIAoYpEZEEDFMiIgkYpkREEjBMiYgkYJgSEUnAMCUikoBhSkQkgbPSBVDfkZycjJKSEkXGDg8Px7Zt2xQZmyyn1GvEHl4f3DMlk5KSEkXeKEqNS72nxHNlL68P7pmSmfDwcHz55Zc2HXPKlCk2HY9uj61fI/by+uCeKRGRBAxTIiIJGKZERBIwTImIJGCYEhFJwDAlIpKAU6OIyGqMRiNOnDiBf//732htbYWHhwdGjx6NsLAwDBw4sEt/IQQyMzMxb9486HQ62xd8GximRCSVEAIHDhzAO++8g/3790MI0aXPwIEDkZCQgJUrVyIyMtK0XGpqKjZu3Ii6ujps3rzZ1qXfljv2MD87O7vXk4E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1IkKV0TXUnTSfktLC4KCgrBt2zYsWrTopn3PnTuH9957D5MmTcKUKVMAANOnT0dJSQmSk5Px0ksvSaururoaWq0WFRUVCA4ONrUHBQVh06ZNPdYqw7qMLKuPQUQ9S09JsqifopP2Dx8+DAcHByxcuLDHvgEBAVi+fDlCQkJQVVWFwYMHIzs7GwcPHjSd05TF09MTwM97qNdqamqCSqWSOtaNWPoE0p2nsfkiXF0G8Ap+H6PoYX59fT28vLzg4OBgUf/29na0tLTg7NmzAIDAwECr1KXRaKDValFcXGxqq6iogNFo7NXpAiJr8FJ7Mkj7IEX3TCMjI1FZWYn8/HzMmjULRqMRer0esbGx6OzsxPbt27FgwQL4+fmhpqYGq1atgk6nQ2hoqNVrS0pKQkZGBh588EF4e3sjJSUFsbGx0Ol0Vh8b4GE+UV9h8VGiUFh2drYYMWKEcHd3FwEBAWL9+vVCCCE6OjrEzJkzha+vr3BzcxN33XWXePLJJ0V5ebnZ8rt37xavvfbaTcfYtGmTuPfee3tVV3t7u1izZo3w9vYWHh4e4tFHHxUXLlzo3R9HRHcMu//WqOzsbNTU1Ei9AEVE1Ft2HaaJiYnQ6/Voa2vDPffcg/z8fKVLIqI7lF2HKRFRX6H4pH0iov6AYUpEJAHDlIhIAoYpEZEEDFMiIgkYpkREEjBMiYgkYJgSEUnAMCUikoBhSkQkAcOUiEgChikRkQQMUyIiCRimREQSMEyJiCRgmBIRScAwJSKSgGFKRCQBw5SISAKGKRGRBAxTIiIJGKZERBIwTImIJGCYEhFJwDAlIpKAYUpEJAHDlIhIgv8Cwt4l1Bq031YAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x264715c8748>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Try both commands:\n",
    "execute_locally(circuit,draw_circuit=True)\n",
    "# execute_circuit(circuit,draw_circuit=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Free flow: Changing the direction of a CNOT gate\n",
    "Check this [application of the CNOT](https://github.com/Qiskit/ibmqx-user-guides/blob/master/rst/full-user-guide/004-Quantum_Algorithms/061-Basic_Circuit_Identities_and_Larger_Circuits.rst#changing-the-direction-of-a-cnot-gate) and try to replicate it using Qiskit!\n",
    "\n",
    " Try to replicate it using the unitary transformations as well, pen and paper is better suited for this.\n",
    "\n",
    "![diagram of the problem](reverse_cnot.png)\n",
    "\n",
    "A CNOT equals Hadamards on both qubits an oposite CNOT and two new Hadamards!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Free flow: Swapping the states of qubits with a CNOT gate\n",
    "Check this [application of the CNOT](https://github.com/Qiskit/ibmqx-user-guides/blob/master/rst/full-user-guide/004-Quantum_Algorithms/061-Basic_Circuit_Identities_and_Larger_Circuits.rst#swapping-the-states-of-qubits) and try to replicate it using Qiskit!\n",
    "\n",
    " Try to replicate it using the unitary transformations as well, pen and paper is better suited for this.\n",
    " \n",
    "![diagram of the problem](swap_with_cnot.png)\n",
    "\n",
    "Three CNOT gates allow 2 qubits to swap their original values, can you do this with 2 classical bits??"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Executing on a remote device\n",
    "If you do this, you may have to wait for some time (usually a few minutes), depending on the current demand of the devices\n",
    "\n",
    "**TASK:** Create a circuit that simply measures 5 qubits and run it on a remote device using `execute_remotely`!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "qr, cr, circuit = new_circuit(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "circuit.measure(qr, cr);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running on current least busy device:  ibmq_16_melbourne\n",
      "Status @ 0 seconds\n",
      "JobStatus.INITIALIZING\n",
      "Status @ 10 seconds\n",
      "JobStatus.RUNNING\n",
      "Status @ 20 seconds\n",
      "JobStatus.RUNNING\n",
      "JobStatus.DONE\n",
      "experiment:  COMPLETED {'00000': 661, '00001': 170, '00010': 6, '00011': 1, '00100': 3, '01000': 114, '01001': 38, '01010': 2, '01011': 2, '10000': 15, '10001': 7, '11000': 5}\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAEtxJREFUeJzt3X+MHOV9x/H3NziQijaxgYMg2/RAcVNQ1QR6pUZUURpXKT/amqi4AlXBpa7cH5CkSqXWNH9UlVqJ5I/SolYEK6QxVZpAaSMsoFDLgPpDgmASYiCGclAHX03wEcDhR345fPvHPBvW573b3btZn/3o/ZJWO/PMs/N9Zmb3s+O5uXNkJpKker1lsQcgSRotg16SKmfQS1LlDHpJqpxBL0mVM+glqXIGvSRVzqCXpMoZ9JJUuSWLPQCAk046KcfHxxd7GJJ0VHn44YdfyMyxfv2OiKAfHx9nx44diz0MSTqqRMQ3BunnpRtJqpxBL0mVM+glqXIGvSRVzqCXpMoZ9JJUOYNekipn0EtS5Qx6SarcEfGbsQsxvunO1te5+9qLW1+nJC0Wz+glqXIGvSRVzqCXpMoZ9JJUOYNekipn0EtS5Qx6SaqcQS9JlTPoJalyBr0kVc6gl6TKGfSSVDmDXpIqZ9BLUuUGCvqIWBoRt0XEExGxKyLOi4gTImJbRDxVnpeVvhER10fEZETsjIhzRrsJkqS5DHpG/7fA3Zn508B7gF3AJmB7Zq4Ctpd5g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7my7TpeHgLcMsT2zuQf4YEQsi4hlwAdprl32257ZbAWuiMZqYH9Z11x1poGfKcdtPTDWZo0B9tmwdXoqx+0+4DSafXY1cEfbdfrofj/NfJ8Ne1xeiYjVERHAb9BcYmu1zjy3sVNntkw5JLO6js0wn435GcWF/1E/aH6K/j80P8n+RGk7o+zUSeCfgeNK+9vK/GRZfkbXej5R1vEkcOGM9U/R3Fr3rRHV+ALNWdYB3ryFayF1dtOcdb9axt75qf4E8Fip9VIL+2y2Op8q82+U7XlxgDo/X17zWtnPj3fV+Z3SfxK4sqt9ru35aFnfAZozo8+U9qD5z3Ceprk1b2LAOrvLe2D/iGrMtc/mU+c/ab6gvlNe+ysz9v9emi/Khe6z2ep8lOYulc5lrteADTTXorfT3EK4HThhgcflsbIdr5X9NjWCOp1jk8APy6NT50Nl+nvA8xz8g9a5MuWgzJrrs9H2w9+MlaTKHY2XbiRJQzDoJalyBr0kVc6gl6TKGfSSVDmDXpIqZ9BLUuUMekmq3P8DIh2v8Ui8XjwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2646f2987b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "execute_remotely(circuit)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Comment on the results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> \n",
    "**Important:** Once you get the results, you may see that, in fact, most of the iterations resulted in `00000`, but you will also see that there will be a few hits on other bit configurations (typically mostly composed of `0`s, like `00001` or `00010`) this is due to **experimental error** on the quantum device and is a concern to take into account when deploying into real devices!!"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
